package service;


import dao.CustomerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Customer;

import java.util.List;

@Service
public class CustomerService {
    @Autowired
    CustomerDao customerDao;


    public Customer queryCustomer(String phone){
        return customerDao.queryCustomer(phone);
    }

    public List<Customer> queryAllCustomer(){
        return customerDao.queryAllCustomer();
    }

    public int addCustomer(Customer customer){
        if(customerDao.queryCustomer(customer.getPhone()) == null){
            return customerDao.insertCustomer(customer);
        }
        return 0;
    }

    public int updateCustomer(Customer customer,String oldPhone ){
        if(customer.getPhone().equals(oldPhone) || customerDao.queryCustomer(customer.getPhone()) == null){
            return customerDao.updateCustomer(customer);
        }
        return 0;
    }

    public int deleteCustomer(String phone){
        return customerDao.deleteCustomer(phone);
    }
}
